package cn.supermaster.management.web.rest.system;

import cn.supermaster.management.common.annotation.Log;
import cn.supermaster.management.common.domain.SystemUser;
import cn.supermaster.management.common.enums.BusinessType;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.web.service.system.ISProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.rest.system
 * @ClassName: SystemProfileRestController
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/10 20:44
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@RestController
@RequestMapping("/system/user/profile")
public class SystemProfileRestController {

    @Autowired
    private ISProfileService profileService;

    @Log(title = "重置密码", businessType = BusinessType.UPDATE)
    @PostMapping("/resetPwd")
    public WebResponse doResetPassword(String oldPassword, String newPassword) {
        return profileService.doResetPassword(oldPassword, newPassword);
    }

    @GetMapping("/checkPassword")
    public boolean checkPassword(String password) {
        return profileService.doCheckPassword(password);
    }

    /**
     * 修改用户
     */
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public WebResponse update(SystemUser user) {
        return profileService.doModifyUserInformation(user);
    }

    /**
     * 保存头像
     */
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updateAvatar")
    public WebResponse updateAvatar(@RequestParam("avatarfile") MultipartFile file) {
        return profileService.doModifyAvatarInformation(file);
    }
}